package com.apes.framework.plugin.soe.metadata;

import com.apes.framework.jpa.ApesBean;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 功能：凭证类型
 *
 * @author xul
 * @create 2018-09-21 14:05
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = BusinessFieldItem.CONST_TABLE_NAME, indexes={@Index(columnList="business_field_id, business_type", unique = true)})
public class BusinessFieldItem implements ApesBean {
    public static final String CONST_TABLE_NAME = "soe_business_field_item";
    @Id
    @Column(name = "id", length = 64)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "模型字段明细表")
    @Comment("编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "business_field_id", referencedColumnName = "id")
    @Comment("模型字段ID")
    private BusinessField businessField;

    @Comment("业务场景模型")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "business_type", referencedColumnName = "id", nullable = false)
    private BusinessType businessType;

    @Column(name = "code", nullable = false, length = 64)
    @Comment("通用名")
    private String code;


}
